

/**
 * 创建entity Plane
 */
import Entity from '../Entity'

export default class Plane extends Entity {

  /**
   * 创建一个Plane实体对象
   * @param {*} position 
   * @param {*} options 
   */
  constructor(positions, options = {}) {
    super()
    this._dimensions = options.dimensions
    this._positions = positions
    this._normal = undefined
    this._type = 'plane'
    if(options.normal == 'x'){
      this._normal = Cesium.Cartesian3.UNIT_X
    }else if(options.normal == 'y'){
      this._normal = Cesium.Cartesian3.UNIT_Y
    }else{
      this._normal = Cesium.Cartesian3.UNIT_Z
    }

    delete options['normal']
    this._style = {...options}

    this.delegate = new Cesium.Entity({
      plane: {
        plane: new Cesium.Plane(this._normal, 0.0)
      }
    })
    this.mounted()
  }

  /**
  * 初始化对象属性
  */

  mounted() {
    this.style = this._style
    this.positions = this._positions
    this.dimensions = this._dimensions
  }

  /** 
  * @param {*} style Circle的样式
  * @returns 
  */

  setStyle(style) {
    if (!style) return
    delete style['position']
    Object.assign(this._style , {...style})
    Object.assign(this.delegate.plane, {...this._style})
  }

  get style(){
    return this._style
  }

  set style(val){
    Object.assign(this._style , {...val})
    Object.assign(this.delegate.plane , {...this._style})
  }
  

  get normal(){
    return this._normal
  }

  set normal(val){
    this._normal = val
    this.normal = this._normal
  }

  get positions() {
    return this._positions
  }

  set positions(val) {
    this._positions = val
    this.delegate.position = this._positions
  }

  get dimensions() {
    return this._dimensions
  }

  set dimensions(val) {
    this._dimensions = val
    this.delegate.plane.dimensions = this._dimensions
  }
}
